package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.CureRecordFileDao;
import cn.topevery.garden.entity.po.CureRecordFile;
import cn.topevery.garden.entity.query.CureRecordFileQuery;
import cn.topevery.garden.entity.vo.CureRecordFileVO;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 防止记录 附件表
 *
 * @author code-generate
 * @date 2022-02-18
 */
@Service
public class CureRecordFileLogic extends BaseLogic<CureRecordFile> {
    @Autowired
    CureRecordFileDao cureRecordFileDao;

    @Override
    public BaseEntityDao<CureRecordFile, Integer> getDao() {
        return cureRecordFileDao;
    }

    

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<CureRecordFileVO> listPage(CureRecordFileQuery query) {
        return cureRecordFileDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        cureRecordFileDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param cureRecordFile 实体
     */
    public void saveOrUpdate(String userId, CureRecordFile cureRecordFile){
        cureRecordFileDao.saveOrUpdate(userId,cureRecordFile);
    }

    /**
         * 根据自定义列值来获取对象
         */
    public CureRecordFile getEntityByColumn(String key, String value) {
        return cureRecordFileDao.getEntityByColumn(key, value);
    }

    public List<CureRecordFile> getListByMainId(Integer mainId) {
        return cureRecordFileDao.getListByMainId(mainId);
    }

    public void saveOrUpdate(String userId, Integer mainId, List<CureRecordFile> fileList) {
        cureRecordFileDao.deleteByMainId(mainId);
        for (CureRecordFile cureRecordFile : fileList) {
            cureRecordFile.setMainId(mainId);
            cureRecordFileDao.saveOrUpdate(userId, cureRecordFile);
        }
    }

    public void deleteByMainIds(Integer[] ids) {
        cureRecordFileDao.deleteByMainIds(ids);
    }
}
